var OrthodonticScoreTable = {//质量管理管理初始化
    id: "OrthodonticScoreTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

function _cellStyles(value, row, index) {
    if (row.status == 1 || row.status == 3) {
        return {css: {"background-color": "#fff1d5", "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    } else {
        return {css: {"overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    }
}

OrthodonticScoreTable.initColumn = function () {//初始化表格的列
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'num', field: 'num', visible: false, align: 'center', valign: 'middle'},
        {title: 'status', field: 'status', visible: false, align: 'center', valign: 'middle'},
        {title: 'submissionState', field: 'submissionState', visible: false, align: 'center', valign: 'middle'},
        {title: 'classification', field: 'classification', visible: false, align: 'center', valign: 'middle'},
        {
            title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传人姓名', field: 'createName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '种类', field: '', align: 'center', valign: 'middle', sortable: true, width: 70,
            formatter: function (value, row, index) {
                return "正畸";
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '门诊', field: 'arrivalStore', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '初诊医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '初诊护士', field: 'nurse', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '复诊医生', field: 'doctor1', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '复诊护士', field: 'nurse1', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation', align: 'center', valign: 'middle', width: 60,
            formatter: function (value, row, index) {
                var ids1 = row.num + "," + row.reservationsId + "," + 1 + "," + 'doctor';
                var ids2 = row.num + "," + row.reservationsId + "," + 2 + "," + 'doctor';
                if(row.status == 1){
                    return '<button title="初诊详情查看" onclick="OrthodonticScoreTable.displayUpdateIconTypes(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button>';
                }else if(row.status == 0){
                    return '<button title="初诊详情修改" onclick="OrthodonticScoreTable.displayUpdateIconTypes1(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button> ' +
                        '<button title="初诊详情删除" onclick="OrthodonticScoreTable.deleteUpdateIconTypes(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
                }else if(row.status == 2 && row.submissionState == 1){
                    return '<button title="初诊详情查看" onclick="OrthodonticScoreTable.displayUpdateIconTypes(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button> ' +
                        '<button title="完成详情修改" onclick="OrthodonticScoreTable.orthodonticComplexDisplay(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button>'+
                    '<button title="完成详情删除" onclick="OrthodonticScoreTable.deleteUpdateIconTypes1(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
                }else if(row.status == 2 ){
                    return '<button title="完成详情修改" onclick="OrthodonticScoreTable.orthodonticComplexDisplay(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-pencil"></span></button>'+
                        '<button title="完成详情删除" onclick="OrthodonticScoreTable.deleteUpdateIconTypes1(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-trash"></span></button>';
                }
                else if(row.status == 3 && row.submissionState == 1){
                    return '<button title="初诊详情查看" onclick="OrthodonticScoreTable.displayUpdateIconTypes(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button> ' +
                        '<button title="完成详情查看" onclick="OrthodonticScoreTable.orthodonticComplexDisplay(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button>';
                }else if(row.status == 3){
                    return '<button title="完成详情查看" onclick="OrthodonticScoreTable.orthodonticComplexDisplay(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button>';
                }
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        }
    ];
};

//正畸初诊图片 - 删除
OrthodonticScoreTable.deleteUpdateIconTypes = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteOrthodonticScore",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                OrthodonticScoreTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};

//正畸完成图片 - 删除
OrthodonticScoreTable.deleteUpdateIconTypes1 = function(ids) {
    if (confirm("是否删除此组数据")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/deleteOrthodonticScore1",
            type: "post",
            data: {"ids": ids},
            success: function (data) {
                OrthodonticScoreTable.search();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        });
    }
};


//正畸初诊图片回显
OrthodonticScoreTable.displayUpdateIconTypes = function (ids) {
    var index = layer.open({
        type: 2,
        title: '正畸初诊图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/orthodonticsDisplay/' + ids
    });
    this.layerIndex = index;
};

//正畸初诊图片回显
OrthodonticScoreTable.displayUpdateIconTypes1 = function (ids) {
    var index = layer.open({
        type: 2,
        title: '正畸初诊图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/orthodonticsDisplay1/' + ids
    });
    this.layerIndex = index;
};

//正畸完成图片回显
OrthodonticScoreTable.orthodonticComplexDisplay = function (ids) {
    var index = layer.open({
        type: 2,
        title: '正畸完成图片回显',
        area: ['85%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/orthodonticComplexDisplay/' + ids
    });
    this.layerIndex = index;
};

OrthodonticScoreTable.orthodonticsMiddle = function () {
    if (this.check()) {
        var num = OrthodonticScoreTable.seItem.num;
        var reservationsId = OrthodonticScoreTable.seItem.reservationsId;
        var ids = num + "," + reservationsId;
        var index = layer.open({
            type: 2,
            title: '上传正畸复诊',
            area: ['85%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/orthodonticsMiddle/' + ids
        });
        this.layerIndex = index;
    }
};

//上传正畸复诊
OrthodonticScoreTable.orthodonticsComplex = function () {
    if (this.check()) {
        var num = OrthodonticScoreTable.seItem.num;
        var reservationsId = OrthodonticScoreTable.seItem.reservationsId;
        var ids = num + "," + reservationsId;
        var index = layer.open({
            type: 2,
            title: '上传正畸复诊',
            area: ['85%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctorLooked/orthodonticsComplex/' + ids
        });
        this.layerIndex = index;
    }
};

OrthodonticScoreTable.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        OrthodonticScoreTable.seItem = selected[0];
        return true;
    }
};

OrthodonticScoreTable.search = function () {//
    OrthodonticScoreTable.table.refresh({query: OrthodonticScoreTable.formParams()});
};

OrthodonticScoreTable.inquire = function () {//人数统计 + 表格刷新
    OrthodonticScoreTable.search();
};

OrthodonticScoreTable.formParams = function () {//查询质量管理列表
    var queryData = {};
    queryData['reservationsId'] = $("#reservationsId").val();
    return queryData;
};

$(function () {

});
